home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
SHOWREC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-23
|
7KB
|
240 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: showrec.c
// Title: Application Template
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
// This module contains the program entry point for
//
// The code in this module may be written in C++ or C.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
//
//----------------------------------------------------------------------------
#include <dio.h>
//----------------------------------------------------------------------------
// Stack size
//----------------------------------------------------------------------------
#if COMPILER_BORLAND && (OS_DOS || OS_WINDOWS)
unsigned _stklen = 0x4000;
#endif
//----------------------------------------------------------------------------
// Globals
//----------------------------------------------------------------------------
//
// A useless string which is simply embedded in the executable.
//
PSZ __pszCredits__ = "Written by John M Weeder, 1993";
//
// This should contain a program description which will be displayed as
// part of the program's help text.
//
static PCSZ pcszDescription =
"This program displays the contents of a stripped fixed length data file.";
//
// Program command line options
//
static BOOL fKey = FALSE;
static BOOL fSorted;
static LONG lDuplicates;
static CHAR szConfig[MAX_PATH] = "data";
static CHAR szInput[MAX_PATH];
static LONG lStart = 0;
static LONG lEnd = 0x7FFFFFFFL;
static LONG lLength = -1;
static BS_CMDOPT acmdopt[] =
{
{ "BEGIN", (PVOID)&lStart, CMDOPT_NUMERIC, "Starting record."},
{ "END", (PVOID)&lEnd, CMDOPT_NUMERIC, "Ending record."},
{ "KEY", (PVOID)&fKey, CMDOPT_TRUE, "Display sort keys."},
{ "LENGTH", (PVOID)&lLength, CMDOPT_NUMERIC, "Number of records to display."},
{ "config", (PVOID)szConfig, CMDOPT_FILESPECR(80),"Configuration file name."},
{ "input", (PVOID)szInput, CMDOPT_FILESPEC(80), "Input file name."},
BS_CMDOPT_NULL,
};
//----------------------------------------------------------------------------
// Description: Call back function to display a record
// Parameters: pdlmrec Record data.
// Returns: 0
//----------------------------------------------------------------------------
static SHORT FN_E ShowRec(PDLMREC pdlmrec)
{
static CHAR szKey[2][MAX_RECORD_LEN+1];
static SIZET cWhich;
static SIZET cKeyLen;
SIZET i, j;
if (pdlmrec->lId < 0) // Initialization/termination codes
{
if (pdlmrec->lId == DAI_INITIALIZE)
{
pdlmrec->pcfg->lNoise = 0;
memset(szKey, 0, sizeof(szKey));
cKeyLen = DataKeyLen(pdlmrec->pcfg);
cWhich = 0;
fSorted = TRUE;
lDuplicates = 0;
}
else if (fKey && pdlmrec->pcfg->fVerbose)
{
if (fSorted)
Output("File is sorted.\n");
else
Output("File is NOT sorted.\n");
Output("%ld duplicate keys.\n", lDuplicates);
}
return 0;
}
if (fKey)
{
CHAR ch = ' ';
SIZET i;
DataKey(pdlmrec, szKey[cWhich]);
if (pdlmrec->lId)
{
int retval = memcmp(szKey[!cWhich], szKey[cWhich], cKeyLen);
if (retval > 0)
{
fSorted = FALSE;
ch = '*';
}
else if (retval == 0)
{
lDuplicates++;
ch = '=';
}
}
if (pdlmrec->pcfg->fVerbose)
{
Output("%c%08ld|%08lX:%04hX ",
ch,
pdlmrec->lId,
pdlmrec->recid.lBlock,
pdlmrec->recid.usOffset);
for (i = 0; i < MIN(16, cKeyLen); ++i)
if (isascii(szKey[cWhich][i]) && isprint(szKey[cWhich][i]))
Output("%c", szKey[cWhich][i]);
else
Output(" ");
Output(" ");
for (i = 0; i < MIN(16, cKeyLen); ++i)
Output("%02lX", (ULONG)(BYTE)szKey[cWhich][i]);
Output("\n");
}
cWhich = !cWhich;
}
else
{
Output("Record=%8ld Offset=%8ld Size=%4ld XRef=%08lX:%04hX\n",
pdlmrec->lId,
(LONG)pdlmrec->pdlmndx->fpos,
(LONG)pdlmrec->pdlmndx->usLen,
pdlmrec->recid.lBlock,
pdlmrec->recid.usOffset);
for (i = 0; i < pdlmrec->pcfg->cFields; ++i)
if (BTEST(pdlmrec->pcfg->afld[i].fs, FLD_FIXED))
{
SIZET cLen = pdlmrec->pcfg->afld[i].cLen;
PSZ psz = pdlmrec->apsz[i];
Output(" %20.20s: '", pdlmrec->pcfg->afld[i].szName);
for (j = 0; j < MIN(16, cLen); ++j)
if (isascii(psz[j]) && isprint(psz[j]))
Output("%c", psz[j]);
else
Output(" ");
Output("' ");
for (j = 0; j < MIN(16, cLen); ++j)
Output("%02lX", (ULONG)(BYTE)psz[j]);
Output("\n");
}
else
{
Output(" %20.20s: '%.40s'\n",
pdlmrec->pcfg->afld[i].szName,
pdlmrec->apsz[i]);
}
}
return 0;
}
//----------------------------------------------------------------------------
// Description: main() - Program entry point
// Parameters: Standard C parameters
// Returns: DOS return code.
//----------------------------------------------------------------------------
int main(int argc, char **argv)
{
static BS_CFG cfg = CFG_DFT;
static DATACFG dcfg;
//
// Initialize base library
//
BaseLibraryInitialize(argc, argv, &cfg);
BaseTitle("$Revision: 93.1 $", __DATE__, __TIME__, "Display Stripped Data Files");
if (!BaseTitleHelp(acmdopt, pcszDescription))
return 99;
if (!DataConfigRead(szConfig, &dcfg))
{
Output("Failed reading configuration file.\n");
return 99;
}
if (szInput[0])
if (!DataConfigFiles(&dcfg, szInput))
return 99;
if (lLength > 0)
lEnd = lStart + lLength - 1;
return DataProcess(&dcfg, lStart, lEnd, ShowRec) ? 0: 99;
}
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------